package com.demo.controller;

import com.alibaba.fastjson.JSONArray;
import com.demo.entity.RoleEntity;
import com.demo.entity.UserEntity;
import com.demo.service.IRoleService;
import com.demo.service.IUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author libo
 * @version 1.0
 * @date 2018/4/26 17:16
 */
@RestController
public class UserController {

    private final Logger LOG = LoggerFactory.getLogger(UserController.class);

    @Autowired
    private IUserService userService;
    @Autowired
    private IRoleService roleService;

    @GetMapping("list")
    public String list() {
        Map<String,Object> params = new HashMap<>();
        params.put("id",5);
        List<UserEntity> userEntities = userService.listByQuery(params);
        JSONArray userArray = new JSONArray();
        userArray.addAll(userEntities);
        LOG.info("=====");
        LOG.info(userArray.toString());
        LOG.info("=====");


        List<UserEntity> userEntities1 = userService.listByQuery(params);
        JSONArray userArray1 = new JSONArray();
        userArray1.addAll(userEntities1);
        LOG.info("=====");
        LOG.info(userArray1.toString());
        LOG.info("=====");



        List<RoleEntity> roleEntities = roleService.listByQuery(params);
        JSONArray roleArray = new JSONArray();
        roleArray.addAll(roleEntities);
        LOG.info("=====");
        LOG.info(roleArray.toString());
        LOG.info("=====");


        List<RoleEntity> roleEntities1 = roleService.listByQuery(params);
        JSONArray roleArray1 = new JSONArray();
        roleArray1.addAll(roleEntities1);
        LOG.info("=====");
        LOG.info(roleArray1.toString());
        LOG.info("=====");
        return "1";
    }
}
